package com.zlz.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zlz.server.mapper.MenuRoleMapper;
import com.zlz.server.pojo.MenuRole;
import com.zlz.server.pojo.RespBean;
import com.zlz.server.service.IMenuRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author efire
 * @since 2021-01-20
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements IMenuRoleService {
    @Resource
    private MenuRoleMapper menuRoleMapper;

    @Override
    @Transactional
    public RespBean updateMenuRole(Long rid, Long[] mids) {
        menuRoleMapper.delete(new QueryWrapper<MenuRole>().eq("role_id", rid));
        if (Objects.isNull(mids) || mids.length == 0) {
            return RespBean.success("更新成功", null);
        }
        menuRoleMapper.updateRecord(rid, mids);
        return RespBean.success("更新成功", null);
    }
}
